package 
{
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.display.DisplayObjectContainer;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.geom.Matrix;
	import flash.geom.Rectangle;
	import org.flixel.FlxCamera;
	import org.flixel.FlxGame;
	
	/**
	 * ...
	 * @author João Brant
	 */
	
	 [Frame(factoryClass="Preloader")] //Tells Flixel to use the default preloader 
	 
	public class Main extends FlxGame 
	{
		private static var testador:DisplayObjectContainer;
		private static var testBitmapDataBig:Bitmap;
		private static var testBitmapDataStamp:BitmapData;
		private static var testadorCount:int = 0;
		public static var frameRate:int = 30;
		public static var delta:Number = 1 / frameRate;
		public static var windowWidth:int = 800;
		public static var windowHeight:int = 600;
		
		public function Main():void 
		{
			super(windowWidth, windowHeight, MenuState, 1, frameRate, frameRate, true);
			testador = this;
		}
		
		private function init(e:Event = null):void 
		{
			
		}
		
		public static function ballTest(x:Number, y:Number):void
		{
			var spr:Sprite = new Sprite();
			
			//Cria novo bitmap
			if (testBitmapDataStamp == null)
			{
				testBitmapDataStamp = new BitmapData(20, 20, true, 0);
				var i:int, j:int;
				for (i = 0; i < 20; i++)
				{
					for (j = 0; j < 20; j++)
					{
						var dX:int = i - 10; var dY:int = j - 10;
						if (dX * dX + dY * dY < 5) testBitmapDataStamp.setPixel32(i, j, 0xffff0000);
					}
				}
			}
			
			if (testBitmapDataBig == null)
			{
				testBitmapDataBig = new Bitmap(new BitmapData(windowWidth, windowHeight, true, 0));
				testador.addChild(testBitmapDataBig);
			}
			
			testadorCount++;
			if (testadorCount % 100 == 0)
			{
				testBitmapDataBig.bitmapData.fillRect(new Rectangle(0, 0, windowWidth, windowHeight), 0);
			}
			var m:Matrix = new Matrix();
			m.translate(x, y);
			testBitmapDataBig.bitmapData.draw(testBitmapDataStamp, m);
			
		}
		
	}
	
}